﻿using System;
using System.Linq;
using System.Collections.Generic;

using MiniSched.Web.Security.Abstractions;

namespace MiniSched.Web.Security.Initialization {

    public class MiniSchedSecurityInitializer {

        internal WebSecurityAbstraction WebSecurity {
            get {
                if (null == _WebSecurity) _WebSecurity = WebSecurityAbstraction.Default;
                return _WebSecurity;
            }
            set {
                if (null == value) throw new ArgumentNullException("WebSecurity");
                _WebSecurity = value;
            }
        }
        private WebSecurityAbstraction _WebSecurity;

        public string ConnectionStringName {
            get { return _ConnectionStringName; }
            set { _ConnectionStringName = value; }
        }
        private string _ConnectionStringName = "MiniSchedContext";

        public string UserTableName {
            get { return _UserTableName; }
            set { _UserTableName = value; }
        }
        private string _UserTableName = "UserProfiles";

        public string UserIdColumn {
            get { return _UserIdColumn; }
            set { _UserIdColumn = value; }
        }
        private string _UserIdColumn = "Id";

        public string UserNameColumn {
            get { return _UserNameColumn; }
            set { _UserNameColumn = value; }
        }
        private string _UserNameColumn = "UserName";

        public bool AutoCreateTables {
            get { return _AutoCreateTables; }
            set { _AutoCreateTables = value; }
        }
        private bool _AutoCreateTables = true;

        public void InitializeSecurity() {
            WebSecurity.InitializeDatabaseConnection(ConnectionStringName, UserTableName, UserIdColumn, UserNameColumn, AutoCreateTables);
        }
    }
}
